# $Id: FilterStatsPiechart.pm,v 1.1 2004/02/29 19:18:42 ibo Exp $

package CGI::FOGE2::FilterStatsPiechart;

use strict;
use CGI::FOGE2::Tools;
our @ISA = qw(CGI::FOGE2::FilterStats);

=head1 SYNOPSIS

StatsPiechart - Generates a pie-chart using the statpic.cgi script.

=cut

sub getstats {
    my $self = shift;
    my ($outpie, $outtable) = ('', '');

    my ($number, $total, $names, $vals) = $self->computedata();
    my $piecgi = 'statpic.cgi/%s%s.png';
    
    $outpie = sprintf $piecgi, 'pieaa', join('_', @$vals);
    $outpie = CGI::img({ src => $outpie, alt => "pie chart",
			 width => 320, height => 240 });
    my $i = 0;
    foreach my $name (@$names) {
	my $bar = sprintf($piecgi, 'bar', $i . '_24_16');
	my $text = CGI::img({ src => $bar, alt => "bar" });
	my $name = CGI::td({class   => 'statrow'}, $name);
	$text = CGI::td({class   => 'statrow'}, $text);
	if ($i==0) {
	    $text = CGI::td({rowspan => scalar @$names,
			     class   => 'statrow'},
			    $outpie).$text;
	}
	$outtable .= CGI::Tr($text . $name);

	++$i;
    }
    $outtable = CGI::table($outtable);

    return $outtable;
}

1;
